home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / text_buf.cpp < prev    next >
C/C++ Source or Header  |  1994-10-10  |  1KB  |  70 lines

  1. #include "text_buf.h"
  2. #include <string.h>
  3.  
  4. TextPage::TextPage()
  5.     {
  6.     page = (uchar**)malloc(sizeof(uchar*) * PAGE_HEIGHT);
  7.     for(int i = 0; i < PAGE_HEIGHT; i++)
  8.     {
  9.     page[i] = (uchar*)malloc(sizeof(uchar) * PAGE_WIDTH);
  10.     memset(page[i], ' ', PAGE_WIDTH);
  11.     page[i][PAGE_WIDTH] = '\0';
  12.     }
  13.     }
  14. //////////////////////////////
  15. TextPage::~TextPage()
  16.     {
  17.     for(int i = 0; i < PAGE_HEIGHT; i++)
  18.     delete page[i];
  19.     delete page;
  20.     }
  21. //////////////////////////////
  22. int TextPage::draw_bar(rect r, char c)
  23.     {
  24.     char str[PAGE_WIDTH];
  25.     memset(str, c, r.width());
  26.     str[r.width() - 1] = '\0';
  27.     int ret;
  28.     for(int j = r.origin.Y; j < r.corner.Y; j++)
  29.     {
  30.     ret = putText(loc(r.origin.X, j), str);
  31.     if(PAGE_HEIGHT < ret)
  32.         return ret;
  33.     }
  34.     return 0;
  35.     }
  36. ///////////////////////////////
  37. int TextPage::putText(loc pos, uchar* txt)
  38.     {
  39.     int i = 0;
  40.     int height = 0;
  41.     loc curr = pos;
  42.     while(txt[i] != '\0')
  43.     {
  44.     switch(txt[i])
  45.         {
  46.         case '\r':   i++; break;
  47.         case '\n':
  48.         curr.X = pos.X;
  49.         curr.Y++;
  50.         i++;
  51.         height++;
  52.         if(curr.Y > PAGE_HEIGHT)
  53.             return height;
  54.         break;
  55.         default:
  56.         if(curr.X > PAGE_WIDTH)
  57.             {
  58.             i++;
  59.             continue;
  60.             }
  61.         page[curr.Y][curr.X] = txt[i];
  62.         i++;
  63.         curr.X++;
  64.         break;
  65.         }
  66.     }
  67.     char* tmp = page[curr.Y];
  68.     return height;
  69.     }
  70.